// 病例合约接口
const blockChainApp = require("../BlockChainApp")
const Config = require("../Config")


module.exports = {
    // 新增病历报告记录
    addCaseReport: async function(param){
        var caseRecordContarct = await blockChainApp.contracts.CaseRecords.deployed()
        // function createCaseRecord(string memory _username, uint _checkDate, uint _finishedDate, string memory _sympton, string memory _doctorUsername, string memory _subject) public {
        return caseRecordContarct.createCaseRecord(param.username, param.checkDate, param.finishedDate, param.sympton, param.doctor, param.subject, {from: Config.executeAccount})
    },

    // 获取所有病历报告记录
    getAllCaseRecords: async function(param){
        var caseRecordContarct = await blockChainApp.contracts.CaseRecords.deployed()
        return caseRecordContarct.findAllCaseRecord.call()
    },

    // 病历信息更新
    updateCaseRecord: async function(param){
        var caseRecordContarct = await blockChainApp.contracts.CaseRecords.deployed()
        // updateCaseRecord(uint32 _id, string memory _username, uint _checkDate, uint _finishedDate, string memory _sympton, string memory _doctorUsername, uint32 _prescriptionId, string memory _subject)
        return caseRecordContarct.updateCaseRecord(param.id, param.username, param.checkDate, param.finishedDate, param.sympton, param.doctor, param.prescriptionId, param.subject, {from: Config.executeAccount})
    },

    // 指定条件参数查询病历信息
    findCaseRecordWithCondition: async function(param){
        var caseRecordContarct = await blockChainApp.contracts.CaseRecords.deployed()
        return caseRecordContarct.findCaseRecord.call(param.username, param.startCheckDate, param.endCheckDate, param.startFinishedDate, param.endFinishedDate, param.subject, param.doctor, {from: Config.executeAccount})
    },

    // 查询指定病历信息
    findCaseRecordWithId: async function(id){
        var caseRecordContarct = await blockChainApp.contracts.CaseRecords.deployed()
        return caseRecordContarct.findCaseRecord.call(id);
    }
}